package com.force.jianghuling.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.force.jianghuling.R;
import com.force.jianghuling.base.BaseActivity;
import com.force.jianghuling.httputils.DataListener;
import com.force.jianghuling.httputils.HttpUtils;
import com.force.jianghuling.utils.TitleBuilder;


/**
 * Created by zzj on 2016/12/12.
 */
public class SignsTestActivity extends BaseActivity implements DataListener{

    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_signstest);
        initView();
    }


    private void initView(){
        initRightTitle("签到页面",R.mipmap.ic_launcher,"签到");
        editText = (EditText) findViewById(R.id.act_signstest_et_content);
    }


    /**
     * 带有右部图标的标题栏
     * @param title
     * @param rightImag
     * @param rightTx
     * @return
     */
    protected TitleBuilder initRightTitle(String title, int rightImag, String rightTx) {
        return new TitleBuilder(this)
                .setTitleText(title)
                .setRightImage(rightImag)
                .setRightText(rightTx)
                .setLeftImage(R.mipmap.ic_back)
                .setLeftOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                })
                .setRightOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String content = editText.getText().toString();
                        HttpUtils.signs(context,SignsTestActivity.this,content);
                    }
                });
    }

    @Override
    public void onSuccess(String json, String type) {
        showLog("获取签到页面的回调数据："+json);
        showToast("签到成功");
        finish();
    }

    @Override
    public void onFail(Exception e, String type) {
        showLog("获取签到页面的失败回调数据："+e.getMessage());
        showToast("签到失败");
    }
}
